package com.java.basis.reference;

import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;

/**
 * @author wangning
 * @date 2023/5/18 15:40
 * 弱引用，只要发生GC就回收
 */
public class WeakReferenceDemo {
    public static void main(String[] args) {
        Object o1 = new Object();
        WeakReference<Object> softReference = new WeakReference<>(o1);
        System.out.println(o1);
        System.out.println(softReference.get());
        o1 = null;
        System.gc();
        System.out.println("************************");
        System.out.println(o1);//null
        System.out.println(softReference.get());//null

    }
}
